<?php
/**
 * Creation de mon screen
 * @var unknown_type
 */
// Mon ecran
$screen = new Screen("TreeGrid Sample");

// DataSource
$ds = new RestDataSource('ds_hierarchy');
$ds->addField(new DataSourceField('ref', Constant::FIELD_TYPE_INTEGER, 'Ref.', true));
$ds->addField(new DataSourceField('name', Constant::FIELD_TYPE_TEXT, 'Name'));
$parent = new DataSourceField('refParent', Constant::FIELD_TYPE_INTEGER);
$parent->set('rootValue', 0);
$parent->set('foreignKey', 'ref');
$ds->addField($parent);
$ds->addField(new DataSourceField('isFolder', Constant::FIELD_TYPE_BOOLEAN));

// ajout des dataSources
$screen->addDataSource($ds);

// La grille
$tree = new TreeGrid('tree_test');
$tree->set('width','100%');
$tree->set('height',200);
$tree->set('showResizeBar', true);
$tree->set('dataSource',$ds->getID());
$tree->set('canRemoveRecords',true);
$tree->set('showConnectors',true);
$tree->set('loadDataOnDemand',true);
$tree->setJSRecordClick("form_test.editSelectedData(viewer);");

// Le formulaire
$df = new DynamicForm('form_test');
$df->set('dataSource',$ds->getID());

// Button
$b = new Button('button_test','Sauvegarder');
$b->setJSAction("form_test.saveData();if (form_test.getSaveOperationType() == 'add') form_test.clearValues();");
// Button
$bn = new Button('button_test2','Nouveau');
$bn->setJSAction("form_test.clearValues();form_test.setSaveOperationType('add');");

// Ajout des elements graphiques
$screen->addMember($tree);
$screen->addMember($bn);
$screen->addMember($df);
$screen->addMember($b);

// Rendu
$screen->render();
?>
